﻿using System.Collections;
using System.Collections.Generic;
using DSL;

class SlkAction
{
    internal SlkAction(SlkToken tokens)
        : base()
    {
        this.tokens = tokens;
        m_StatementList = new List<StatementData>();
    }

    private SlkToken tokens;

    private List<StatementData> m_StatementList;

    private FunctionData m_CurFunc;
    private StatementData m_CurStatement;
    private FunctionCallData m_CurFuncCall;

    internal class  SemanticeInfo
    {
        public string token;
        public int type;
    }

    public void state(int number) { }

    // -----------------------------------------------------------------------
    // grammar action code functions
    // -----------------------------------------------------------------------


    public void execute(int number)
    {
        switch (number)
        {
            case 1: beginStatement(); break;
            case 2: endStatement(); break;
            case 3: beginFunction(); break;
            case 4: endFunction(); break;
            case 5: beginParam(); break;
            case 6: endParam(); break;
            case 7: pushNum(); break;
            case 8: pushStr(); break;
            case 9: pushTrue(); break;
            case 10: pushFalse(); break;
            case 11: pushId(); break;
        }
    }

    public void reduce(short production_number)
    {
        //short[] production = SlkParser.GetProductionArray(production_number);
        //short rhs;
        //int length,
        //        index = 0,
        //        debug = 0,
        //        rhs_length;

        // Console.WriteLine(SlkString.GetProductionName(production_number));
    }
    private void pushId()
    {
    }

    private void pushFalse()
    {
        var valueData  = new ValueData();
        valueData.SetBool(false);
        m_CurFuncCall.AddValueData(valueData);
    }

    private void pushTrue()
    {
        var valueData = new ValueData();
        valueData.SetBool(true);
        m_CurFuncCall.AddValueData(valueData);
    }

    private void pushStr()
    {
        var valueData = new ValueData();
        valueData.SetString(tokens.getCurToken());
        m_CurFuncCall.AddValueData(valueData);
    }

    private void pushNum()
    {
        var valueData = new ValueData();
        valueData.SetNum(tokens.getCurToken());
        m_CurFuncCall.AddValueData(valueData);
    }

    private void endFunction()
    {
        m_CurFunc = null;
    }

    private void beginParam()
    {
        m_CurFuncCall = new FunctionCallData();
        m_CurFunc.SetFunctionCallData(m_CurFuncCall);
    }

    private void endParam()
    {
        m_CurFuncCall = null;
    }

    private void beginFunction()
    {
        m_CurFunc = new FunctionData();
        m_CurStatement.SetFunctionData(m_CurFunc);
    }

    private void endStatement()
    {
        m_CurStatement = null;
    }

    private void beginStatement()
    {
        m_CurStatement = new StatementData();
        if (m_CurFunc != null)
        {
            m_CurFunc.AddStatement(m_CurStatement);
        }
    }
};
